package com.maxd.service.lucky;

import com.maxd.model.LuckyValueQueue;
import com.maxd.respository.lucky.LuckyValueQueueJpaRepository;
import com.maxd.respository.lucky.LuckyValueQueueRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 幸运值队列
 */
@Service
public class LuckyValueQueueServiceImpl implements ILuckyValueQueueService {

    private final LuckyValueQueueJpaRepository luckyValueQueueJpaRepository;
    private final LuckyValueQueueRepository luckyValueQueueRepository;

    public LuckyValueQueueServiceImpl(LuckyValueQueueJpaRepository luckyValueQueueJpaRepository, LuckyValueQueueRepository luckyValueQueueRepository) {
        this.luckyValueQueueJpaRepository = luckyValueQueueJpaRepository;
        this.luckyValueQueueRepository = luckyValueQueueRepository;
    }

    @Override
    public LuckyValueQueue saveBody(LuckyValueQueue luckyValueQueue) {
        return luckyValueQueueJpaRepository.save(luckyValueQueue);
    }

    @Override
    public int updateLuckyValueQueue(Long userId, Long luckyQueueId,Integer state, String createTime) {
        return luckyValueQueueRepository.updateLuckyValueQueue(userId,luckyQueueId,state,createTime);
    }

    @Override
    public LuckyValueQueue selectLuckyValueQueueByUserId(Long userId) {
        return luckyValueQueueRepository.selectLuckyValueQueueByUserId(userId);
    }

    @Override
    public Integer selectUserLuckyQueueByInvitation(String invitation, Integer sort) {
        return luckyValueQueueRepository.selectUserLuckyQueueByInvitation(invitation,sort);
    }

    @Override
    public Integer selectLuckQueueLocationByUserId(Long userId, Long luckyQueueId) {
        return luckyValueQueueRepository.selectLuckQueueLocationByUserId(userId,luckyQueueId);
    }

    @Override
    public Integer selectLuckQueueCount(Long luckyQueueId) {
        return luckyValueQueueRepository.selectLuckQueueCount(luckyQueueId);
    }

    @Override
    public List<Map<String, Object>> selectLuckQueueLocation(Long luckyQueueId) {
        return luckyValueQueueRepository.selectLuckQueueLocation(luckyQueueId);
    }

    @Override
    public Map<String, Object> selectLuckQueueLocationByUserIds(String invitation,Long userId, Long luckyQueueId) {
        if((invitation == null) || "".equals(invitation)){
            invitation="-1";
        }
        return luckyValueQueueRepository.selectLuckQueueLocationByUserIds(invitation,userId,luckyQueueId);
    }

    @Override
    public Page<Map<String, Object>> selectLuckyQueueByUser(Pageable pageable, String invitation) {
        return luckyValueQueueRepository.selectLuckyQueueByUser(pageable,invitation);
    }

    @Override
    public int updateLuckyValueQueue(Integer state, Long id) {
        return luckyValueQueueRepository.updateLuckyValueQueue(state, id);
    }

    @Override
    public List<Long> selectLuckyQueueUserIdByLuckyQueueId(Long luckyQueueId) {
        return luckyValueQueueRepository.selectLuckyQueueUserIdByLuckyQueueId(luckyQueueId);
    }

}
